package com.yanqu.road.entity.activity.jiuzhou;

import com.yanqu.road.entity.DataObject;
import com.yanqu.road.entity.DataStatus;
import com.yanqu.road.entity.FieldTypeAnnotation;

import java.math.BigInteger;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 玩家用户信息
 */
@FieldTypeAnnotation(tableName = "t_c_jiu_zhou_user_data")
public class CrossJiuZhouUserData extends DataObject {

    @FieldTypeAnnotation(desc = "活动ID", select = true, update = true)
    private int activityId;

    @FieldTypeAnnotation(desc = "玩家ID", update = true)
    private long userId;

    @FieldTypeAnnotation(desc = "每一轮的房间id")
    private Map<Integer, Integer> roomIdMap = new HashMap<>();

    @FieldTypeAnnotation(desc = "缓存赚钱")
    private BigInteger patronsAbility;

    @FieldTypeAnnotation(desc = "所在赛区类型")
    private int zoneType;

    @FieldTypeAnnotation(desc = "最大晋级轮次")
    private int lastRoundId;

    @FieldTypeAnnotation(desc = "轮次记录")
    private Map<Integer, CrossJiuZhouUserRoundRecordData> recordDataMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "人气值")
    private Map<Integer, Long> popularityMap = new ConcurrentHashMap<>();

    @FieldTypeAnnotation(desc = "门客数据")
    private Map<Integer, CrossJiuZhouPatronsData> patronsDataMap = new ConcurrentHashMap<>();


    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if (this.activityId != activityId) {
            this.activityId = activityId;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, Integer> getRoomIdMap() {
        return roomIdMap;
    }

    public void setRoomIdMap(Map<Integer, Integer> roomIdMap) {
        if (roomIdMap == null) {
            return;
        }
        this.roomIdMap = roomIdMap;
        setOp(DataStatus.Update);
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if (this.userId != userId) {
            this.userId = userId;
            setOp(DataStatus.Update);
        }
    }

    public int getZoneType() {
        return zoneType;
    }

    public void setZoneType(int zoneType) {
        if (this.zoneType != zoneType) {
            this.zoneType = zoneType;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, CrossJiuZhouUserRoundRecordData> getRecordDataMap() {
        return recordDataMap;
    }

    public CrossJiuZhouUserRoundRecordData getRecordData(int round) {
        return recordDataMap.get(round);
    }

    public void setRecordDataMap(Map<Integer, CrossJiuZhouUserRoundRecordData> recordDataMap) {
        if (recordDataMap == null) {
            return;
        }
        this.recordDataMap = recordDataMap;
        setOp(DataStatus.Update);
    }

    public BigInteger getPatronsAbility() {
        return patronsAbility;
    }

    public void setPatronsAbility(BigInteger patronsAbility) {
        if (patronsAbility == null) {
            return;
        }
        this.patronsAbility = patronsAbility;
        setOp(DataStatus.Update);
    }

    public int getLastRoundId() {
        return lastRoundId;
    }

    public void setLastRoundId(int lastRoundId) {
        if (this.lastRoundId != lastRoundId) {
            this.lastRoundId = lastRoundId;
            setOp(DataStatus.Update);
        }
    }

    public Map<Integer, CrossJiuZhouPatronsData> getPatronsDataMap() {
        return patronsDataMap;
    }

    public void setPatronsDataMap(Map<Integer, CrossJiuZhouPatronsData> patronsDataMap) {
        if (patronsDataMap == null) {
            return;
        }
        this.patronsDataMap = patronsDataMap;
        setOp(DataStatus.Update);
    }

    public void changePatronsData(CrossJiuZhouPatronsData patronsData) {
        synchronized (patronsDataMap) {
            patronsDataMap.put(patronsData.getPatronsId(), patronsData);
            setOp(DataStatus.Update);
        }
    }

    public void addRoomId(int roundId, int roomId) {
        roomIdMap.put(roundId, roomId);
        setOp(DataStatus.Update);
    }

    public int getRoomId(int roundId) {
        return roomIdMap.getOrDefault(roundId, -1);
    }

    /**
     * 增加人气值
     *
     * @param round
     * @param addValue
     */
    public void addPopularity(int round, long addValue) {
        popularityMap.put(round, popularityMap.getOrDefault(round, 0L) + addValue);
        setUpdateOption();
    }

    public Map<Integer, Long> getPopularityMap() {
        return popularityMap;
    }

    public void setPopularityMap(Map<Integer, Long> popularityMap) {
        if (popularityMap == null) {
            return;
        }
        this.popularityMap = popularityMap;
        setOp(DataStatus.Update);
    }
}
